package com.praveen.twu.managers;

import com.praveen.twu.item.Account;

import java.util.HashMap;

/**
 * Created by praveen on 20/6/14.
 */
public class LoginManager {

    private static HashMap<String, Account> credentials = new HashMap<String, Account>();
    private static String loggedInUser = null;

    public static void initialize() {
        credentials.clear();
        credentials.put("1000-100", new Account("1000-100", "1100", "Tester One", "tester1@gmail.com", "9009009000"));
        credentials.put("1000-101", new Account("1000-101", "1101", "Tester Two", "tester2@gmail.com", "9009009001"));
        credentials.put("1000-110", new Account("1000-110", "1110", "Tester Three", "tester3@gmail.com", "9009009002"));
        credentials.put("1000-111", new Account("1000-111", "1111", "Tester Four", "tester4@gmail.com", "9009009003"));
        loggedInUser = null;
    }

    public static boolean login(String username, String password) {
        if (credentials.containsKey(username) && ((Account) credentials.get(username)).getPassword().equals(password)) {
            loggedInUser = username;
            return true;
        } else return false;
    }

    public static Account getAccount() {
        if (loggedInUser != null)
            return credentials.get(loggedInUser);
        else
            return null;
    }

    public static boolean isLoggedIn() {
        return loggedInUser != null;
    }
}
